package com.exonline.backstage.controller.teacher;

import com.exonline.commons.base.IBaseService;
import com.exonline.backstage.entity.Teacher;
import com.exonline.commons.dao.DaoImpl;
import com.exonline.commons.dao.IDao;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

public class TeacherService implements IBaseService<Teacher> {
    IDao<Teacher> dao = new DaoImpl<>();

    @Override
    public List<Teacher> queryAll(int pageSize, int pageNo) throws SQLException {
        return null;
    }

    public List<Teacher> queryAllReview(int pageSize, int pageNo) throws SQLException {
        List<Teacher> teachers = dao.queryWithPagingAndConditions("SELECT * FROM reviewteacherview", null, pageNo, pageSize, new BeanListHandler<>(Teacher.class), null);
        return teachers;
    }
    public List<Teacher> query(int pageSize, int pageNo) throws SQLException {
        return null;
    }

    @Override
    public Teacher queryOne(String id) throws SQLException {
        return null;
    }

    @Override
    public void add(Object... obj) throws SQLException {

        dao.updateWithTransaction("INSERT INTO  teacher(id,tname,workyears,direction,introduce,email,phone,password,status) values(?,?,?,?,?,?,?,?,?)",obj);
    }

    @Override
    public void update(Object... obj) throws SQLException {

    }

    @Override
    public void deleteById(String id) throws SQLException {

    }

    public void doReview(String id,String tid, String comment,String status) throws SQLException {
        if (status.equals("1")) {
            dao.updateWithTransaction("UPDATE teacher set status = 1 where id = ?",tid);
            dao.updateWithTransaction("INSERT INTO reviewhistory(id,tid,status,comment) values(?,?,?,?)",id,tid,"1",comment);
        }
        else{
            dao.updateWithTransaction("UPDATE teacher set status = 2 where id = ?",tid);
            dao.updateWithTransaction("INSERT INTO reviewhistory(id,tid,status,comment) values(?,?,?,?)",id,tid,"2",comment);
        }
    }
}
